home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / BG_SRC.ZIP / BG_GRAF3.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-16  |  7.5 KB  |  251 lines

  1. /*
  2.  *                     B  G  _  G  R  A  F  3  .  C
  3.  *         A graphics module for the backgammon playing program BG.C.
  4.  *                   This version  23rd January 1993
  5.  *
  6.  */
  7.  
  8. #include "comp.h"
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <malloc.h>
  13. #include "bg.h"
  14.  
  15. /*************************************************************************/
  16.  
  17. extern Disp_Cfg_t Disp_Cfg ; /* Imported from BG_GRAF1.C */
  18. extern Screen_Const_t Grafs ;
  19.  
  20. /*************************************************************************/
  21. #define PMASK 0x80
  22. /*lint -e569   */
  23. char Bg_String [] = {' ' | PMASK,'B',' ' | PMASK,' ' | PMASK,'A' | PMASK,' ' | PMASK,' ' | PMASK,'C' | PMASK,' ' | PMASK,' ' | PMASK,'K' | PMASK,' ' | PMASK,' ' | PMASK,'G' | PMASK,' ' | PMASK,' ' | PMASK,'A' | PMASK,' ' | PMASK,' ' | PMASK,'M' | PMASK,' ' | PMASK,' ' | PMASK,'M' | PMASK,' ' | PMASK,' ' | PMASK,'O' | PMASK,' ' | PMASK,' ' | PMASK,'N' | PMASK,' ',NUL} ;
  24. char Sws_String [] = {' ' | PMASK,'b','y' | PMASK,' ' | PMASK,'C' | PMASK,'U','S' | PMASK,'T','O' | PMASK,'M' | PMASK,'A' | PMASK,'T' | PMASK,'I' | PMASK,'X' | PMASK,' ',NUL} ;
  25. /*lint +e569   */
  26. void Title_Page (void)
  27. /*
  28. PURPOSE: To draw the title page of BG.EXE.
  29. */
  30. {
  31.     Demask (Bg_String) ;
  32.     Demask (Sws_String) ;
  33.     Framed_Center_String (Bg_String,TITLE_BG_ROW,OVERWRITE) ;
  34.     Framed_Center_String (Sws_String,TITLE_SWS_ROW,OVERWRITE) ;
  35.     Framed_Center_String (VER_STR,TITLE_VER_ROW,OVERWRITE) ;
  36.     Init_Faces () ;
  37. }
  38.  
  39. /*************************************************************************/
  40.  
  41. typedef struct {
  42.     void*  Ptr ;
  43.     int    Size ;
  44.     short  x0,y0,x1,y1 ;
  45. } Pushed_Image_t ;
  46.  
  47. static Pushed_Image_t P_Image ;
  48. static boolean Pushed = FALSE ;
  49.  
  50. /*************************************************************************/
  51.  
  52. void Framed_Center_String (char* String, short Row, FCS_Op_t Operation)
  53. /*
  54. PURPOSE: To draw the string in the center of the screen at Row.
  55.          The background rectangle is set to black.
  56.          The string is 'framed'.
  57. NOTES:   1) If Operation is OVERWRITE then we do not save what was below
  58.          the string rectangle.
  59.          2) If Operation is PUSH then we save what was below, ready to
  60.          be popped by Erase_Center_String
  61. */
  62. {
  63.     short x,y,N_Chars,Wide,High,Col ;
  64.  
  65.  
  66.     N_Chars = strlen (String) ;
  67.     Col     = (Disp_Cfg.Text_Cols/2) - (N_Chars/2) ;
  68.  
  69.     x    = (Col * Disp_Cfg.Char_Wide) - MARGIN ;
  70.     y    = (Row * Disp_Cfg.Char_High) - MARGIN ;
  71.     Wide = (N_Chars * Disp_Cfg.Char_Wide) + (2*MARGIN) ;
  72.     High = Disp_Cfg.Char_High + (2*MARGIN) ;
  73.  
  74.     if (Operation == PUSH) {
  75.         if (Pushed == TRUE) {
  76.             Error_Exit ("Pushing when already pushed") ;
  77.         }
  78.         P_Image.x0 = x ;
  79.         P_Image.y0 = y ;
  80.         P_Image.x1 = x + Wide + 1 ;
  81.         P_Image.y1 = y + High + 1 ;
  82.         P_Image.Size = imagesize (P_Image.x0,P_Image.y0,P_Image.x1,P_Image.y1) ;
  83.         P_Image.Ptr  = malloc ((size_t)P_Image.Size) ;
  84.         if (P_Image.Ptr == NULL) {
  85.             Error_Exit ("Cannot malloc for pushed image") ;
  86.         }
  87.         getimage (P_Image.x0,P_Image.y0,P_Image.x1,P_Image.y1,P_Image.Ptr) ;
  88.         Pushed = TRUE ;
  89.     }
  90.  
  91.     Fill_Rect (x,y,Wide,High,BLACK) ;
  92.     Graf_Text (Row,Col,String,WHITE) ;
  93.  
  94.     Draw_Rect (x,y,Wide,High,WHITE) ;
  95.     Draw_Line (x,y+High,x+Wide-1,y+High,WHITE) ; /* Underline bottom line */
  96. }
  97.  
  98. /*************************************************************************/
  99.  
  100. void Erase_Framed_String (void)
  101. /*
  102. PURPOSE: To restore the area of the screen erased by the last
  103.          Framed_Center_String operation.
  104. */
  105. {
  106.     if (!Pushed) {
  107.         Error_Exit ("Trying to pop an unpushed image") ;
  108.     }
  109.  
  110.     putimage (P_Image.x0,P_Image.y0,P_Image.Ptr,COPY_PUT) ;
  111.  
  112.     free (P_Image.Ptr) ;
  113.  
  114.     Pushed = FALSE ;
  115. }
  116.  
  117. /*************************************************************************/
  118.  
  119. void Clear_Screen (void)
  120. /*
  121. PURPOSE: To clear the whole graphics screen.
  122. */
  123. {
  124.     Fill_Rect (0,0,Disp_Cfg.X_Pixels,Disp_Cfg.Y_Pixels,BLACK) ;
  125. }
  126.  
  127. /*************************************************************************/
  128. #if DRODBAR
  129. void Draw_Prob_Diag (char Disp[6][6])
  130. /*
  131. PURPOSE: To draw in the Logo_Area the probability diagram passed.
  132. */
  133. {
  134.     short w,h,x,y,c,d0,d1 ;
  135.  
  136.     /* Clear the logo away
  137.     Fill_Rect (Grafs.Logo_X,Grafs.Logo_Y,
  138.                Grafs.Logo_Wide,Grafs.Logo.High,BLACK) ; */
  139.  
  140.     Draw_Rect (Grafs.Logo_X,Grafs.Logo_Y,
  141.                Grafs.Logo_Wide,Grafs.Logo_High,WHITE) ;
  142.  
  143.     w = (Grafs.Logo_Wide / 6) ;
  144.     h = (Grafs.Logo_High / 6) ;
  145.  
  146.     for (d0 = 0 ; d0 < 6 ; d0++) {
  147.         x = Grafs.Logo_X + (w*d0) ;
  148.         for (d1 = 0 ; d1 < 6 ; d1++) {
  149.             y = Grafs.Logo_Y + (h*d1) ;
  150.             if (Disp[d0][d1]) {
  151.                 c = WHITE ;
  152.             } else {
  153.                 c = BLACK ;
  154.             }
  155.             Fill_Rect (x,y,w,h,c) ;
  156.         }
  157.     }
  158. }
  159. #endif
  160. /*************************************************************************/
  161.  
  162. void Draw_Pline (short N_Points, short Line[][2], short Col)
  163. /*
  164. PURPOSE: To draw a polyline, not closed.
  165. */
  166. {
  167.     short i ;
  168.     for (i = 0 ; i < (N_Points-1) ; i++) {
  169.     Draw_Line (Line[i][0],Line[i][1],
  170.            Line[i+1][0],Line[i+1][1],Col) ;
  171.     }
  172. }
  173.  
  174. /***************************************************************************/
  175.  
  176. void Draw_Pgon (short N_Points, short Line[][2], short Col)
  177. /*
  178. PURPOSE: To draw a closed polyline, i.e. a polygon.
  179. */
  180. {
  181.     Draw_Pline (N_Points,Line,Col) ;
  182.     Draw_Line (Line[0][0],Line[0][1],
  183.                Line[N_Points-1][0],Line[N_Points-1][1],Col) ;
  184. }
  185.  
  186. /***************************************************************************/
  187.  
  188. void Draw_Double_Button (void)
  189. /*
  190. PURPOSE: To draw the square at the center of the bar which is
  191.          used as DOUBLE button.
  192. */
  193. {
  194.     short x,y ;
  195.  
  196.     /* Draw the rectangle */
  197.     Draw_Rect (Grafs.Double_X+2,Grafs.Double_Y+2,Grafs.Unit_Wide,Grafs.Unit_High,WHITE) ;
  198.  
  199.     /* Draw the 'D' char inside the rectangle */
  200.     x = Grafs.Double_X + 2 + (Grafs.Unit_Wide/2) - (Disp_Cfg.Char_Wide/2) ;
  201.     y = Grafs.Double_Y + 2 + (Grafs.Unit_High/2) - (Disp_Cfg.Char_High/2) ;
  202.     Text_At_Pixel (x,y,"D",WHITE) ;
  203. }
  204.  
  205. /***************************************************************************/
  206.  
  207. void Draw_Double_Cube (Player_t Possesor, short Number)
  208. /*
  209. PURPOSE: To draw the doubling cube at the end of the BAR next to the
  210.          player who has possession.
  211. */
  212. {
  213.     char Buffer[4] ;
  214.     short x,y,Num_Wide,Cube_Row,Clear_Row ;
  215.  
  216.     if (Possesor == WHITE_PLAYER) {
  217.         Cube_Row  = 0 ;
  218.         Clear_Row = 11 ;
  219.     } else if (Possesor == BLACK_PLAYER) {
  220.         Cube_Row  = 11 ;
  221.         Clear_Row = 0 ;
  222.     } else {
  223.         return ;
  224.     }
  225.  
  226.     /* Clear the old cube... */
  227.     Get_Grid_Corner (&x,&y,BAR_COL,Clear_Row) ;
  228.     /* Draw the rectangle */
  229.     Fill_Rect (x+2,y+2,Grafs.Unit_Wide,Grafs.Unit_High,BLACK) ;
  230.  
  231.  
  232.     /* Draw the new cube... */
  233.     Get_Grid_Corner (&x,&y,BAR_COL,Cube_Row) ;
  234.  
  235.     /* Draw the rectangle */
  236.     Draw_Rect (x+2,y+2,Grafs.Unit_Wide,Grafs.Unit_High,WHITE) ;
  237.  
  238.     /* Draw the number char inside the rectangle */
  239.     sprintf (Buffer,"%d",Number) ;
  240.     if (Number > 8) {
  241.         Num_Wide = Disp_Cfg.Char_Wide*2 ;
  242.     } else {
  243.         Num_Wide = Disp_Cfg.Char_Wide ;
  244.     }
  245.     x = x + 2 + (Grafs.Unit_Wide/2) - (Num_Wide/2) ;
  246.     y = y + 2 + (Grafs.Unit_High/2) - (Disp_Cfg.Char_High/2) ;
  247.     Text_At_Pixel (x,y,Buffer,WHITE) ;
  248. }
  249.  
  250. /***************************************************************************/
  251.